#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 1e6 + 10, INF = 0x3f3f3f3f;

int n;
vector<string> a;
string t;
int id[N], cnt[N];
int tr[N][26], fail[N], ed[N], idx;

int h[N], e[N], ne[N], tt;
void add(int a, int b) { e[tt] = b, ne[tt] = h[a], h[a] = tt++; }

int insert(string& s)
{
    int p = 0;
    for (char it : s) {
        int c = it - 'a';
        if (tr[p][c] == 0) tr[p][c] = ++idx;
        p = tr[p][c];
    }
    ed[p]++;
    return p;
}

void setfail()
{
    queue<int> q;
    for (int i = 0;i < 26;i++) if (tr[0][i]) { q.push(tr[0][i]); }
    while (!q.empty()) {
        int now = q.front();q.pop();
        for (int i = 0;i < 26;i++) {
            if (tr[now][i]) {
                fail[tr[now][i]] = tr[fail[now]][i];
                q.push(tr[now][i]);
            } else tr[now][i] = tr[fail[now]][i];
        }
    }
}

void dfs(int x)
{
    for (int i = h[x];i != -1;i = ne[i]) {
        int y = e[i];
        dfs(y); cnt[x] += cnt[y];
    }
}

void solve()
{
    memset(h, -1, sizeof h);
    cin >> n;
    for (int i = 1;i <= n;i++) {
        string c;cin >> c;
        id[i] = insert(c);
    }
    setfail();
    cin >> t;
    int p = 0;
    for (char it : t) {
        p = tr[p][it - 'a'];
        cnt[p]++;
    }

    for (int i = 1;i <= idx;i++)
        add(fail[i], i);
    dfs(0);

    for (int i = 1;i <= n;i++)
        cout << cnt[id[i]] << '\n';
}


signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}